/*
 * ProgressStatusPublisher.h
 *
 *  Created on: Dec 25, 2014
 *      Authors: Avihay Avitan & Stefan Farcas
 */

#ifndef PROGRESSSTATUSPUBLISHER_H_
#define PROGRESSSTATUSPUBLISHER_H_
#include "../ProgressStatusConnection/ProgressStatusConnection.h"
#include "../ProgressStatus/ProgressStatus.h"
#include <queue>
#include <boost/thread.hpp>
#include <mutex>

using namespace std;

namespace ProgressStatusSpace {

/**
 * ProgressStatusPublisher - Class that implements the publisher pattern to provide a progress status to an external process
 */
class ProgressStatusPublisher {
public:
	ProgressStatusPublisher();
	virtual ~ProgressStatusPublisher();
	bool publishProgressStatus(ProgressStatus toSend);

private:
	void publisherWorker();
	ProgressMessage * convertStatusToMessage(ProgressStatus toSend);
	ProgressStatusConnection publisher;
	mutex m;
	queue<ProgressMessage *> statusq;
	boost::thread * workerThread;
};

} /* namespace ProgressStatusSpace */

#endif /* PROGRESSSTATUSPUBLISHER_H_ */
